package com.flong.kotlin.utils

import org.apache.commons.lang3.StringUtils

open class ObjectUtil {

    /**
     * @param object
     * *
     * @return
     */
    fun isNull(`object`: Any?): Boolean {
        return if (null == `object`) true else false
    }

    /**
     * @param object
     * *
     * @return
     */
    fun isNotNull(`object`: Any): Boolean {
        return !isNull(`object`)
    }

    /**
     * @param string
     * *
     * @return
     */
    fun isEmpty(string: String): Boolean {
        return StringUtils.isEmpty(string)
    }

    fun isNotEmpty(string: String): Boolean {
        return StringUtils.isNotEmpty(string)
    }
	
	fun stringToBytes(hexString: String?): ByteArray? {
		var hexString = hexString
		if (hexString == null || hexString == "") {
			return null
		}
		hexString = hexString.toUpperCase()
		val length = hexString.length / 2
		val hexChars = hexString.toCharArray()
		val d = ByteArray(length)
		for (i in 0..length - 1) {
			val pos = i * 2
			d[i] = (charToByte(hexChars[pos]).toInt() shl 4 or charToByte(hexChars[pos + 1]).toInt()).toByte()
		}
		return d
	}

	/**
	 * Convert char to byte
	 * @param c char
	 * *
	 * @return byte
	 */
	private fun charToByte(c: Char): Byte {

		return "0123456789ABCDEF".indexOf(c).toByte()
	}
}
